package com.xr.oa.remind;

import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.SqlDataset;
import com.bstek.dorado.common.*;
import com.xr.common.CommUtil;

/**
 * DatasetListener
 */
public class DatasetListener extends AbstractDatasetListener {
	hrHomePageViewModel hrp=new hrHomePageViewModel();
	
  public boolean beforeLoadData(Dataset dataset)
     throws Exception {
	  int tipType = dataset.parameters().getInt("TIP_TYPE");
	  SqlDataset ds = (SqlDataset) dataset;
	  String sql="";
	  if(tipType==1){
		   sql="select emp.employee_code,emp.employee_name,d.dept_name,d.dept_name_full,p.position_name from " +
			"PB_SYS_REMIND_SUB srs,org_employee emp,org_onoff_station oos,org_dept d,pb_position p where" +
			" oos.onoff_station_id=srs.onoff_station_id and oos.position_id=p.position_id " +
			"and srs.expire_date between trunc(sysdate,'d')+1 and trunc(sysdate,'d')+7 " +
			"and oos.employee_id=emp.employee_id and oos.dept_id=d.dept_id " +
			"and exists(select 1 from PB_SYS_REMIND_USER sru where sru.sys_remind_user_id=srs.sys_remind_user_id and sru.sys_remind_id in(1,2) and sru.employee_id="+CommUtil.getEmployeeId()+")";
		  
		  
	  }
	  if(tipType==2){
		  sql="select emp.employee_code,emp.employee_name,d.dept_name,d.dept_name_full,p.position_name from emp_laborcontract el,org_onoff_station oos,org_dept d,org_employee emp,pb_position p where oos.employee_id=emp.employee_id and oos.dept_id=d.dept_id and el.onoff_station_id=oos.onoff_station_id and oos.position_id=p.position_id and el.end_date  between trunc(sysdate,'month')  and last_day(trunc(sysdate,'month'))";
		  
	  }	
	  if(tipType==3){
		  sql="select emp.employee_code,emp.employee_name,d.dept_name,d.dept_name_full,p.position_name from emp_laborcontract el,org_onoff_station oos,org_dept d,org_employee emp,pb_position p where oos.employee_id=emp.employee_id and oos.dept_id=d.dept_id and el.onoff_station_id=oos.onoff_station_id and oos.position_id=p.position_id and el.end_date  between  trunc(add_months(sysdate,1),'month')  and last_day(trunc(add_months(sysdate,1),'month'))";
		 
	  }
	  if(tipType==4){
		  sql="select emp.employee_code,emp.employee_name,d.dept_name,d.dept_name_full,p.position_name from emp_laborcontract el,org_onoff_station oos,org_dept d,org_employee emp,pb_position p where oos.employee_id=emp.employee_id and oos.dept_id=d.dept_id and el.onoff_station_id=oos.onoff_station_id and and oos.position_id=p.position_id el.try_end_date  between trunc(sysdate,'d')+1  and trunc(sysdate,'d')+7";
		  
	  }
	  if(tipType==5){
		  sql="select emp.employee_code,emp.employee_name,d.dept_name,d.dept_name_full,p.position_name from emp_laborcontract el,org_onoff_station oos,org_dept d,org_employee emp,pb_position p where oos.employee_id=emp.employee_id and oos.dept_id=d.dept_id and el.onoff_station_id=oos.onoff_station_id and oos.position_id=p.position_id and el.try_end_date  between trunc(sysdate,'month')  and last_day(trunc(sysdate,'month'))";
		  
	  }
	  if(tipType==6){
		  sql="select emp.employee_code,emp.employee_name,d.dept_name,d.dept_name_full,p.position_name from org_onoff_station oos,org_dept d,org_employee emp,pb_position p where oos.employee_id=emp.employee_id and oos.dept_id=d.dept_id and oos.position_id=p.position_id and oos.work_start_date between trunc(sysdate,'d')+1  and trunc(sysdate,'d')+7";
		  
	  }
	  if(tipType==7){
		  sql="select emp.employee_code,emp.employee_name,d.dept_name,d.dept_name_full,p.position_name from org_onoff_station oos,org_dept d,org_employee emp,pb_position p where oos.employee_id=emp.employee_id and oos.dept_id=d.dept_id and oos.position_id=p.position_id and oos.work_start_date  between trunc(sysdate,'month')  and last_day(trunc(sysdate,'month'))";
		  
	  }
	  if(tipType==8){
		  sql="select emp.employee_code,emp.employee_name,d.dept_name,d.dept_name_full,p.position_name from org_onoff_station oos,org_dept d,org_employee emp,pb_position p where oos.employee_id=emp.employee_id and oos.dept_id=d.dept_id and oos.position_id=p.position_id and oos.work_start_date  between trunc(sysdate,'year')  and last_day(add_months(trunc(sysdate,'year'),12))";
		  
	  }
	  if(tipType==9){
		  sql="select emp.employee_code,emp.employee_name,d.dept_name,d.dept_name_full,p.position_name from org_onoff_station oos,org_dept d,org_employee emp,pb_position p where oos.employee_id=emp.employee_id and oos.dept_id=d.dept_id and oos.position_id=p.position_id and oos.work_end_date  between trunc(sysdate,'d')+1  and trunc(sysdate,'d')+7";
	 
	  }
	  if(tipType==10){
		  sql="select emp.employee_code,emp.employee_name,d.dept_name,d.dept_name_full,p.position_name from org_onoff_station oos,org_dept d,org_employee emp,pb_position p where oos.employee_id=emp.employee_id and oos.dept_id=d.dept_id and oos.position_id=p.position_id and oos.work_end_date  between trunc(sysdate,'month')  and last_day(trunc(sysdate,'month'))";
		   
	  }
	  if(tipType==11){
		  sql="select emp.employee_code,emp.employee_name,d.dept_name,d.dept_name_full,p.position_name from org_onoff_station oos,org_dept d,org_employee emp,pb_position p where oos.employee_id=emp.employee_id and oos.dept_id=d.dept_id and oos.position_id=p.position_id and oos.work_end_date  between trunc(sysdate,'year')  and last_day(add_months(trunc(sysdate,'year'),12))";  
		 
	  }
	  if(tipType==12){
		  sql="select emp.employee_code,emp.employee_name,d.dept_name,d.dept_name_full,p.position_name from org_onoff_station oos,org_dept d,org_employee emp,pb_position p where oos.employee_id=emp.employee_id and oos.dept_id=d.dept_id and oos.position_id=p.position_id and to_date(to_char(sysdate,'YYYY')||to_char(nvl(work_start_date,sysdate),'MMDD'),'yyyyMMdd') between trunc(sysdate,'month')  and last_day(trunc(sysdate,'month')) ";  
		  
	  }
	  sql+=CommUtil.setConditionSQL(ds);
	  ds.setSql(sql);
    return true;
  }

}
